﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using BLL.Users;
using BLL.Users.Impl;
using Utils;

public partial class Page_Register_RegisterOfEnterprise : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    //Next
    protected void btnRegisterEnterpriseNext_Click(object sender, ImageClickEventArgs e)
    {
        string userName = txtRegisterEnterpriseUserName.Text.Trim();
        string userPassword = txtRegisterEnterprisePassword.Text.Trim();
        string email = txtRegisterEnterpriseEmail.Text.Trim();
        string securityQuestion = txtRegisterEnterpriseSecurityQuestion.Text.Trim();
        string securityAnswer = txtRegisterEnterpriseSecurityAnswer.Text.Trim();
        string enterpriseName = txtRegisterEnterpriseEnterpriseName.Text.Trim();
        string phone = txtRegisterEnterprisePhone.Text.Trim();
        string address = txtRegisterEnterpriseAddress.Text.Trim();
        string city = txtRegisterEnterpriseCity.Text.Trim();
        string state = listRegisterEnterpriseState_Province.Text.Trim();
        string postCode = txtRegisterEnterprisePostalCode.Text.Trim();
        string enterpriseType = listRegisterEnterpriseEnterpriseType.Text.Trim();
        string introduce = txtRegisterEnterpriseIntroduce.Text.Trim();
        User user = new User()
        {
            UserId = userName,
            UserPassword = userPassword,
            UserType = "Enterprise",
            SecurityQuestion = securityQuestion,
            SecurityAnswer = securityAnswer,
            Visible = 1
        };
        Enterprise enterprise = new Enterprise()
        {
            EnterpriseId=userName,
            EnterpriseAddress=address,
            EnterpriseCity=city,
            EnterpriseEmail=email,
            EnterpriseIntroduce=introduce,
            EnterpriseName=enterpriseName,
            EnterprisePhone=phone,
            EnterprisePostalCode=postCode,
            EnterpriseProvince=state,
            EnterpriseType=enterpriseType
        };
        UserManageBO userManageBO = new UserManageBOImpl();
        string resultStr = userManageBO.Register(user, enterprise);

        if (resultStr.Equals("Register succeed"))
        {
            Response.Write(WebUtil.GetTipsAndRedirect(resultStr, Request.Url, "Home.aspx"));
        }
        else 
        {
            Response.Write(WebUtil.GetTipsAndRedirect(resultStr, Request.Url, "Register/RegisterOfEnterprise.aspx"));
        }
    }


    //Previous
    protected void btnRegisterEnterprisePrevious_Click(object sender, ImageClickEventArgs e)
    {
        Response.Write("<script language=javascript>history.go(-2);</script>");
    }

    
}